package kr.saeildadim.androidexam_saeildamil.chapter12;

import kr.saeildadim.androidexam_saeildamil.R;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.ArrayAdapter;
import android.widget.Spinner;
import android.widget.Toast;

public class CH12_SpinnerEx extends Activity {
	ArrayAdapter<CharSequence> adspin;
	boolean mInitSpinner;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
	
		super.onCreate(savedInstanceState);
		setContentView(R.layout.ch12_spinnerex);
		
		Spinner spin = (Spinner) findViewById(R.id.ch12_spinner_spinner);
		spin.setPrompt("나라를선택하시요");
		
		adspin = ArrayAdapter.createFromResource(this, R.array.country, android.R.layout.simple_spinner_dropdown_item);
		adspin.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
		spin.setAdapter(adspin);
		
		spin.setOnItemSelectedListener(new OnItemSelectedListener() {

			@Override
			public void onItemSelected(AdapterView<?> parent, View view,
					int position, long id) {
				
				if(mInitSpinner==false){
					mInitSpinner =true;
					return;
				}
					Toast.makeText(CH12_SpinnerEx.this, adspin.getItem(position), Toast.LENGTH_LONG).show();
			}

			@Override
			public void onNothingSelected(AdapterView<?> arg0) {
			}
		});
		
	}
}
